在wordpress帖子/页面中调用ajax 您所在的位置:网站首页 ajax 语法 在wordpress帖子/页面中调用ajax

在wordpress帖子/页面中调用ajax

2022-12-27 07:12| 来源: 网络整理| 查看: 265

Sorry for this but I searched the whole web for a solution to my probleme but in vain :(

对不起,但我在整个网络搜索我的问题的解决方案,但徒劳:(

What I want to achieve is creating a normal Post and adding a form to it that once submitted, goes to a database and gets back a value.

我想要实现的是创建一个普通的Post并向其添加一个表单,一旦提交,就转到数据库并获取一个值。

I created a plugin for that and integrated it in the admin menu then set a function that queries the db :

我为它创建了一个插件并将其集成到管理菜单中,然后设置一个查询db的函数:

myfunc_getcode($db, $table, $value, $return) // returns a value

how can I achieve this!? I mean, when a user inserts some data in the form (that exists inside a post or page) then he clicks on submit, Ajax talks to the db and gets the results back.

我怎么能实现这个目标!?我的意思是,当用户在表单中插入一些数据(存在于帖子或页面中)时,他点击提交,Ajax与数据库对话并获得结果。

I don't even know if wordpress 3.0.1 allows such things!

我甚至不知道wordpress 3.0.1是否允许这样的事情!

1 个解决方案 #1

0  

I got it to work by using

我通过使用它得到了它

add_action('the_content', 'my_function');

this hooks my plugin to the posts and pages.

这将我的插件挂钩到帖子和页面。

then in the function I transmit the content like;

那么在函数中我传输的内容就像;

function my_function($content) {}

Then I used Ajax by integrating jquery inside my script;

然后我通过在我的脚本中集成jquery来使用Ajax;

jQuery(document).ready(function($) {}

for submitting forms I used jquery/ajax to listen to the form

对于提交表单,我使用jquery / ajax来收听表单

$("#my_form_id").submit(function() {

and used jquery's $.post to pass variables to a php page that handeles my results and returns them by echo.

并使用jquery的$ .post将变量传递给php页面,该页面处理我的结果并通过echo返回它们。

hope this helps someone!

希望这有助于某人!



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有